/**
 * Created by xwang on 2018-07-09.
 */
var request = require("superagent");
var API = require("./support/const");
var service = require("../../service/log");


/**
 * 获取整改进度
 * **/
exports.correctiveLog = {
    list: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.get(API.corrective.corrective_log_list)
            .set(header)
            .query({msg: JSON.stringify(req.body)})
            .end(function (_req, _res) {
                // if (_res.status === 200) {
                //     service.save_user_log({'type': 'getList', 'msg': '高校获取整改进度'}, req);
                // }
                res.json(JSON.parse(_res.text));
            });
    },
    adminList: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.get(API.corrective.corrective_list)
            .set(header)
            .query({msg: JSON.stringify(req.body)})
            .end(function (_req, _res) {
                // if (_res.status === 200) {
                //     service.save_user_log({'type': 'getList', 'msg': '管理员获取整改进度'}, req);
                // }
                res.json(JSON.parse(_res.text));
            });
    },
    info: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.get(API.corrective.corrective_info)
            .set(header)
            .query({msg: JSON.stringify(req.body)})
            .end(function (_req, _res) {
                // if (_res.status === 200) {
                //     service.save_user_log({'type': 'getList', 'msg': '获取整改报告详情'}, req);
                // }
                res.json(JSON.parse(_res.text));
            });
    },
    update: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.post(API.corrective.corrective_info_update)
            .type('application/json')
            .set(header)
            .send(JSON.stringify(req.body))
            .end(function (_req, _res) {
                // if (_res.status === 200) {
                //     service.save_user_log({'type': 'edit', 'msg': '更新整改报告详情', 'mark': req.body }, req);
                // }
                res.json(JSON.parse(_res.text));
            });
    }
};

/**
 * 提交报告
 * **/
exports.Report = {
    submit: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.post(API.corrective.corrective_submit_report)
            .set(header)
            .query({msg: JSON.stringify(req.body)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'edit', 'msg': '提交整改报告'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    submitFormalFile: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.post(API.corrective.corrective_submit_report_formal_file)
            .set(header)
            .query({msg: JSON.stringify(req.body)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'edit', 'msg': '提交整改报告正式文件'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    expertAudit: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.post(API.corrective.expert_audit_report)
            .set(header)
            .query({msg: JSON.stringify(req.body)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'edit', 'msg': '专家审核整改报告'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    eduAudit: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.post(API.corrective.edu_audit_report)
            .set(header)
            .query({msg: JSON.stringify(req.body)})
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'edit', 'msg': '教育部审核整改报告'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    getFileUrl: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };

        request.get(`${API.common.get_file}${req.body.id}`)
            .set(header)
            .end(function (_req, _res) {
                if (_res.status === 200) {
                    service.save_user_log({'type': 'edit', 'msg': '教育部审核整改报告'}, req);
                }
                res.json(JSON.parse(_res.text));
            });
    },
    generate_report_word: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.get(`${API.corrective.generate_report_word}`)
            .set(header)
            .query({msg: JSON.stringify(req.body)})
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    }
};

